﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Luna;
using Luna.Framework;

namespace VulnDB.Action.DataCollectors {
	public partial class ActionParameterForm : Form {
		private IActionable action;
		private Predicate<IActionable> validate;
		
		public ActionParameterForm() {
			InitializeComponent();
			btnOK.Click += new EventHandler(btnOK_Click);
		}

		public static bool showPropertyForm(IActionable action) {
			ActionParameterForm form = new ActionParameterForm();
			form.Text = action.Name + " Parameters";
			form.Action = action;
			return (form.ShowDialog() == DialogResult.OK);
		}

		public IActionable Action {
			get { return this.action; }
			set {
				propertyGrid.SelectedObject = action = value;
			}
		}

		void btnOK_Click(object sender, EventArgs e) {
			try {
				if (validate == null || validate(action))
					this.DialogResult = DialogResult.OK;
			}
			catch (ApplicationException ex) {
				MessageBox.Show(ex.Message, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
	}
}
